package com.tanhua.server.controller;

import com.tanhua.server.exception.TaoHuaxEception;
import com.tanhua.server.service.TaoHuaService;
import com.tanhua.server.vo.TaoHuaVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;


@RestController
@RequestMapping("peachblossom")
public class TaoHuaController {
    @Autowired
    private TaoHuaService taoHuaService;

    /**
     * 发语音
     * @param soundFile
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> saveSound(@RequestParam(value = "soundFile") MultipartFile soundFile) {

        try {
            if (null != soundFile) {
                Boolean save = this.taoHuaService.saveSound(soundFile);

                if (save) {
                    return ResponseEntity.ok(null);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();


    }


    @GetMapping
    public ResponseEntity<TaoHuaVo> findSound(){
        try {
            TaoHuaVo sound = this.taoHuaService.findSound();
            if (null!=sound){
                return ResponseEntity.ok(sound);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
